package com.igeek.mygh.TTLQueue;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;


/**
 * @author xlz;
 * @data 2022-08-09 19:41
 */
@Slf4j
@Component
public class SendMsgUtil {


    @Autowired(required = false)
    private RabbitTemplate rabbitTemplate;
    //将信息放入延时队列
    //1.手机号  2.信息内容  3.延迟时间 单位/分钟
    public void sendDelayedMsg(String phone,String msg,Integer ttl){
        String message = phone+msg;
        log.info(message);
        rabbitTemplate.convertAndSend(
                DelayedQueueConfig.DELAYED_EXCHANGE_NAME,
                DelayedQueueConfig.DELAYED_ROUTING_KEY,
                message,m->{
                    m.getMessageProperties().setDelay(ttl*60000);
                    return m;
                }
        );
    }


}
